<template>
  <div class="view-wrapper">
    <div class="head">
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
        <el-form-item label="" prop="query">
          <el-input v-model="queryParams.query" placeholder="请输入手机号\用户昵称\姓名" clearable @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="任务类型" prop="taskType">
          <el-select v-model="queryParams.taskType" placeholder="请选择" clearable style="width: 240px">
            <el-option v-for="dict in taskList" :key="dict.id" :label="dict.value" :value="dict.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="奖励时间">
          <el-date-picker clearable v-model="date" type="daterange" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
            range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" @change="changeTime"
            placeholder="选择下单时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="listBox">
      <div style="margin-bottom: 14px">
        <export-excel-button title="神椰任务奖励明细列表" action="/douyin/task/award/export"  :params="ExportParams" />
      </div>
      <el-table v-loading="loading" :data="issueOrderList" stripe border @selection-change="handleSelectionChange">
        <el-table-column type="index" label="序号" width="55" align="center" fixed />
        <el-table-column label="昵称/姓名" align="center" prop="userName" :show-overflow-tooltip="true" />          
        <el-table-column label="手机号" align="center" prop="userPhone" :show-overflow-tooltip="true" />
        <el-table-column label="任务类型" align="center" prop="taskType" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <dict-tag :options="taskList" :value="scope.row.taskType" />
          </template>
        </el-table-column>
        <el-table-column label="奖励积分" align="center" prop="awardType" :show-overflow-tooltip="true" />
        <el-table-column label="奖励" align="center" prop="awardAmount" :show-overflow-tooltip="true" />
        <el-table-column label="奖励时间" align="center" prop="createTime" :show-overflow-tooltip="true" />
        <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
      </el-table>
      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>
  </div>
</template>

<script>
  import {
    adminDict,
    taskList,
  } from "@/api/dyTask";
  import ExportExcelButton from "@/components/ExportExcelButton/index";

  export default {
    name: "EquityCardBill",
    // dicts: ['equity_card_bill_type'],
    components: {
      ExportExcelButton,
    },
    props: {
      settleNo: String, //结算单号
    },
    data() {
      return {
        // 遮罩层
        loading: false,
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 数字权益卡购卡账单查询表格数据
        issueOrderList: [],
        // 查询参数
        queryParams: {
          query: '', //手机号/用户昵称/姓名
          startTime: '',
          endTime: '',
          pageNum: 1,
          pageSize: 10,
          taskType: '', //任务类型 shenye_douyin_task_type 1注册任务 2 关注主播 3分享小程序任务 4加入粉丝群任务
        },
        date: [],
        taskList: [],
       
      };
    },
    computed: {
      ExportParams() {
        const params = {
          ...this.queryParams,
        };
        return params;
      },
    },
    created() {
      this.getDict()
      this.getList(); 
    },

    methods: {
      getDict() {
        //获取商户类型字典
        const params = {
          dictType: "shenye_douyin_task_type ",
        };
        adminDict(params).then((res) => {
          this.taskList = res.result[0].dictList;
        });
      },
      getList() {
        this.loading = true;
        this.queryParams.exportIdList = []
        taskList(this.queryParams).then(response => {
          response.result.records.forEach(item => {
            for (var key in item) {
              if (item[key]==='') {
                item[key] = "-";
              }
            }
          });
        this.issueOrderList = response.result.records;
          this.total = response.result.total;
          this.loading = false;
        });
      },
      // 表单重置
      reset() {
        this.queryParams = {
          query: '', //手机号/用户昵称/姓名
          startTime: '',
          endTime: '',
          pageNum: 1,
          pageSize: 10,
          taskType: '', //任务类型 shenye_douyin_task_type 1注册任务 2 关注主播 3分享小程序任务 4加入粉丝群任务
        };
        this.date = []
      },
      changeTime(time) {
        if (!time) {
          this.date = []
          this.queryParams.startTime = ''
          this.queryParams.endTime = ''
        } else {
          this.queryParams.startTime = this.date[0]
          this.queryParams.endTime = this.date[1]
        }
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.reset()
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.queryParams.exportIdList = selection.map(item => item.id)
        console.log('this.exportIdList',this.queryParams.exportIdList)
        console.log('this.queryParams',this.queryParams)
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.$refs.dialog.open();
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.$refs.dialog.open(row.id);
      },
      /** 详情按钮操作 */
      handleView(row) {
        this.$refs.dialog.open(row.id, true);
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除？').then(() => {
          this.loading = true;
          return delEquityCardBill(ids);
        }).then(() => {
          this.loading = false;
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).finally(() => {
          this.loading = false;
        });
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$modal.confirm('是否确认导出所有数字权益卡购卡账单查询数据项？').then(() => {
          this.exportLoading = true;
          return exportEquityCardBill(queryParams);
        }).then(response => {
          this.$download.name(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
      }
    }
  };

</script>
<style lang="scss" scoped>
  .head {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    padding: 20px 20px 0;
  }

  .listBox {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    //   height: 120px;
    padding: 20px 20px;
    margin-top: 10px;
  }

  .el-input {
    width: 390px;
  }

</style>
